/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JanelaAdiciona.java
 *
 * Created on Apr 8, 2011, 7:42:26 PM
 */

package spoc.interfaces;

import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author arthur
 */
public class JanelaAdiciona extends javax.swing.JDialog {

    protected JButton botaoOK;
    protected Painel painel;

    /** Creates new form JanelaAdiciona */
    public JanelaAdiciona() {
        initComponents();
        
        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        
        Dimension tamanhoJanela = new Dimension(580, 390);
        
        setMinimumSize(tamanhoJanela);
        setPreferredSize(tamanhoJanela);

        painel = new Painel();

        getContentPane().add(painel, java.awt.BorderLayout.CENTER);

        botaoOK = new JButton();
        java.awt.GridBagConstraints gridBagConstraints;

        botaoOK.setText("OK");
        botaoOK.setEnabled(false);
        botaoOK.setMinimumSize(new java.awt.Dimension(35, 24));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 5;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.ipadx = 60;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(5,5,5,5);
        painel.add(botaoOK, gridBagConstraints);
        this.setLocationRelativeTo(this.getContentPane());

        ListSelectionModel cellSelectionModel = painel.tabela.getSelectionModel();
        cellSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        cellSelectionModel.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                if(painel.tabela.getSelectedRow() != -1){
                    botaoOK.setEnabled(true);
                } else {
                    botaoOK.setEnabled(false);
                }
            }
        });
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JanelaAdiciona().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

    protected void reiniciar(){
        botaoOK.setEnabled(false);
        DefaultTableModel dm = (DefaultTableModel) painel.tabela.getModel();
        dm.getDataVector().removeAllElements();
        painel.campoPesquisa.setText("");
        painel.comboPesquisa.setSelectedIndex(0);
    }
}
